var http = createRequestObject();
//var GLOBAlVAlue='';
function createRequestObject(){
    var obj;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        obj = new XMLHttpRequest();
    }
    return obj;    
}


function sendReqTObackENDTOexeCUTE(serverFileName, argument)

{  
	//alert(argument)
	//alert( serverFileName+'?'+argument);
	http.open('get', serverFileName+'?'+argument);
    http.onreadystatechange = handleResponse;
    http.send(null);
	
}
function handleResponse() 
{
	if(http.readyState == 4)
	{
		if(http.status == 200) {	
			var responseText = http.responseText;
			//alert(http.responseText);
			var final_result=responseText.split("#---#");
			//alert(final_result[0]);alert(final_result[1]);
			var GETseparationVARIAble=final_result[1];
			GETseparationVARIAble=GETseparationVARIAble.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
			//alert(GETseparationVARIAble)
			var GETresulTAFterSEPAraTIOn=final_result[0].split(GETseparationVARIAble);
			var GETARRAYlength=GETresulTAFterSEPAraTIOn.length;
			var i=0
			while( i < GETARRAYlength )
			{
				var GETtheOUTPUT=GETresulTAFterSEPAraTIOn[i].replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
				var GETtheID1=GETresulTAFterSEPAraTIOn[parseInt(i+1)].replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
				var GETtheID2=GETresulTAFterSEPAraTIOn[parseInt(i+2)].replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
				var GETtheID3=GETresulTAFterSEPAraTIOn[parseInt(i+3)].replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
				var GETtheID4=GETresulTAFterSEPAraTIOn[parseInt(i+4)].replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
				
				//alert(GETtheOUTPUT+"--GETtheID1="+GETtheID1 +'--GETtheID2='+GETtheID2+'--GETtheID3='+GETtheID3+'--GETtheID4='+GETtheID4);
				if(GETtheOUTPUT != 'none')
				{
					document.getElementById(GETtheID1).innerHTML=GETtheOUTPUT;
				}
				else
				{
					document.getElementById(GETtheID2).innerHTML=GETtheOUTPUT;
				}
					if(document.getElementById(GETtheID1) != null)
					document.getElementById(GETtheID1).style.display='';
					if(document.getElementById(GETtheID3) != null)
					document.getElementById(GETtheID3).disabled=false;
					if(document.getElementById(GETtheID4) != null)
					document.getElementById(GETtheID4).disabled=true;
					if(document.getElementById(GETtheID2) != null)
					document.getElementById(GETtheID2).style.display='none';
					
				i=parseInt(i+5);
			}
			
		}
		
    }
}


function sendReqTObackENDTOexeCUTEPICKer(serverFileName, argument)//Function for to show Video

{  
	//alert(argument)
	//alert( serverFileName+'?'+argument);
	http.open('get', serverFileName+'?'+argument);
    http.onreadystatechange = handleResponsePICker;
    http.send(null);
	
}

function handleResponsePICker() 
{
	if(http.readyState == 4)
	{
		if(http.status == 200) {	
			var responseText = http.responseText;
			//alert(http.responseText);
			var final_result=responseText.split("--##--");
			//alert(final_result[0]);alert(final_result[1]);
			var GETseparationVARIAble=final_result[1];
			GETseparationVARIAble=GETseparationVARIAble.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
			//alert(GETseparationVARIAble)
			var GETresulTAFterSEPAraTIOn=final_result[0].split(GETseparationVARIAble);
			//alert(GETresulTAFterSEPAraTIOn[1]);
			//alert(parseInt(GETresulTAFterSEPAraTIOn[1]) +(1));
			var IDHOLd=parseInt(GETresulTAFterSEPAraTIOn[1]) +(1);
			//alert(document.getElementById('select'+IDHOLd))
			if(document.getElementById('select'+IDHOLd) != null)
			{
				document.getElementById('select'+IDHOLd+'.'+IDHOLd).innerHTML=GETresulTAFterSEPAraTIOn[0];
				document.getElementById('select'+IDHOLd).disabled=false;																										 
			}
			IDHOLd++;
			for(var i=IDHOLd; i<=5;i++)
			{
				if(document.getElementById('select'+i) != null)
				{
					document.getElementById("select"+i+'.'+i).innerHTML='<select name="select'+i+'" id="select'+i+'"><option value="" selected="selected">---Select One---</option></select>';
					document.getElementById('select'+i).disabled = true;
				}
			}
			
		}
		
    }
}




function sendReqTObackENDTOexecuteAlerts(serverFileName)

{  
	//alert(argument)
	//alert( serverFileName+'?'+argument);
	http.open('get', serverFileName);
    http.onreadystatechange = handleResponseAlerts;
    http.send(null);
	
}


function DHTMLSound(surl) 
{
	//alert(surl);
	if(document.getElementById("ForBlowAlert") != null)
	document.getElementById("ForBlowAlert").innerHTML="<embed src='"+surl+"' hidden=true autostart=true loop=false>";
	//aaa();
	//setTimeout("aaa()",20000);
}


function handleResponseAlerts() 
{
	if(http.readyState == 4)
	{
		if(http.status == 200) {	
			var responseText = http.responseText;
			//alert(responseText);
			responseText = responseText.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
			//alert(http.responseText);
			if(responseText !='')
			{
				//alert("if")
				responseTextField=responseText.split("##__##");
				//alert(responseTextField.length)
				var CounTer=0;
				if(responseTextField[CounTer] != '')
				{
					//alert(GlobalSymbolArray.length);
					for(var i=0; i<GlobalSymbolArray.length;i++)
					{
						//alert(GlobalSymbolArray[i])
						//var CounTer=0;
						
						if(GlobalSymbolArray[i] == responseTextField[CounTer])
						{
							CounTer++;
							//alert(parseFloat(GlobalArray[GlobalSymbolArray[i]][0])+' == '+parseFloat(responseTextField[CounTer])+' ||  '+parseFloat(GlobalArray[GlobalSymbolArray[i]][1])+' == '+parseFloat(responseTextField[CounTer])+' || '+ parseFloat(GlobalArray[GlobalSymbolArray[i]][2])+' == '+parseFloat(responseTextField[CounTer])+" || "+ parseFloat(GlobalArray[GlobalSymbolArray[i]][3])+' == '+parseFloat(responseTextField[CounTer]) );
							if(parseFloat(GlobalArray[GlobalSymbolArray[i]][0]) == parseFloat(responseTextField[CounTer]) ||  parseFloat(GlobalArray[GlobalSymbolArray[i]][1]) == parseFloat(responseTextField[CounTer]) ||  parseFloat(GlobalArray[GlobalSymbolArray[i]][2]) == parseFloat(responseTextField[CounTer]) ||  parseFloat(GlobalArray[GlobalSymbolArray[i]][3]) == parseFloat(responseTextField[CounTer]) )
							{
								if(document.getElementById(GlobalSymbolArray[i]+'_LastvaLue') != null)
								document.getElementById(GlobalSymbolArray[i]+'_LastvaLue').innerHTML=responseTextField[CounTer];
								CounTer++;
								//alert(responseTextField[CounTer])
								if(GlobalArray[GlobalSymbolArray[i]][4] == 'y' || GlobalArray[GlobalSymbolArray[i]][4] == 'Y')
								{
									//alert("sadasdas");
									if(document.getElementById(GlobalSymbolArray[i]+'_image') != null)
									{
										var ImagEsrC=document.getElementById(GlobalSymbolArray[i]+'_image').src;
										//alert(ImagEsrC)
										var ImagEsrCFinaL=ImagEsrC.split("/");
										//alert(ImagEsrCFinaL.length);
										var iMaGe='';
										for(var k=0;k<parseInt(ImagEsrCFinaL.length - 1);k++)
										{
											//alert(ImagEsrCFinaL[k]);
											if(iMaGe == '')
											{
												iMaGe=ImagEsrCFinaL[k]+'/';
											}
											else
											{
												iMaGe +=ImagEsrCFinaL[k]+'/';
											}
											
										}
										var BLOW=responseTextField[CounTer].split(".");
										//alert(document.getElementById(GlobalSymbolArray[i]+'_image').src)
										document.getElementById(GlobalSymbolArray[i]+'_image').src=iMaGe+responseTextField[CounTer];
										//alert(document.getElementById(GlobalSymbolArray[i]+'_image').src)
										//alert(BLOW[0]);
										if(BLOW[0] == 'Yellow' || BLOW[0] == 'yellow' )
										{
											DHTMLSound('Sounds/MARKETDOWN/FirstSell.mp3');
										}
										else if(BLOW[0] == 'Red' || BLOW[0] == 'red' )
										{
											DHTMLSound('Sounds/MARKETDOWN/MaxLoss.wav');
										}
										else if(BLOW[0] == 'Green' || BLOW[0] == 'green' )
										{
											DHTMLSound('Sounds/MARKETDOWN/MustSell.mp3');
										}
										GlobalArray[GlobalSymbolArray[i]][4]='n';
										CounTer++;
									}
								}
								//alert(responseTextField[CounTer]);
							}
							else
							{
								//alert(GlobalArray[GlobalSymbolArray[i]][4]);
								//alert(responseTextField[CounTer])
								if(document.getElementById(GlobalSymbolArray[i]+'_LastvaLue') != null)
								document.getElementById(GlobalSymbolArray[i]+'_LastvaLue').innerHTML=responseTextField[CounTer];
								GlobalArray[GlobalSymbolArray[i]][4]='y';
								CounTer=parseInt(CounTer+2);
							}
							//alert(CounTer);
						}
					}
				}
			}
		}
		
    }
}


function sendReqTObackENDTOexecuteDisplay(serverFileName,Argument)

{  
	//alert(argument)
	//alert( serverFileName+'?'+argument);
	http.open('get', serverFileName+'?DisplayId='+Argument);
    http.onreadystatechange = handleResponseDisplay;
    http.send(null);
	
}

function handleResponseDisplay() 
{
	if(http.readyState == 4)
	{
		if(http.status == 200) {	
			var responseText = http.responseText;
			//alert(http.responseText);
			var final_result=responseText.split("#---#");
			//alert(final_result[0]);alert(final_result[1]);
			var GETseparationVARIAble=final_result[1];
			GETseparationVARIAble=GETseparationVARIAble.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
			//alert(GETseparationVARIAble)
			var GETresulTAFterSEPAraTIOn=final_result[0].split(GETseparationVARIAble);
			var GETARRAYlength=GETresulTAFterSEPAraTIOn.length;
			var i=0
			while( i < GETARRAYlength )
			{
				//alert(GETresulTAFterSEPAraTIOn[i])
				i++;
				if(document.getElementById(GETresulTAFterSEPAraTIOn[i]) != null)
				{
					document.getElementById(GETresulTAFterSEPAraTIOn[i]).innerHTML=GETresulTAFterSEPAraTIOn[0];
				}
				
			}
			
		}
		
    }
}







function sendReqTObackENDTOtotalWeeks(serverFileName, argument) //showing total number of weeks
{  
	//alert(argument)
	//alert( serverFileName+'?'+argument);
	http.open('get', serverFileName+'?'+argument);
    http.onreadystatechange = handleResponseForbackENDTOtotalWeeks;
    http.send(null);
	
}
function handleResponseForbackENDTOtotalWeeks() 
{
	if(http.readyState == 4)
	{
		if(http.status == 200) {	
			var responseText = http.responseText;
			//alert(http.responseText);
			var final_result=responseText.split("#---#");
			//alert(final_result[0]);alert(final_result[1]);
			var GETseparationVARIAble=final_result[1];
			GETseparationVARIAble=GETseparationVARIAble.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
			//alert(GETseparationVARIAble)
			var GETresulTAFterSEPAraTIOn=final_result[0].split(GETseparationVARIAble);
			var GETARRAYlength=GETresulTAFterSEPAraTIOn.length;
			var i=0
			while( i < GETARRAYlength )
			{
				//alert(GETresulTAFterSEPAraTIOn[i])
				i++;
				if(document.getElementById(GETresulTAFterSEPAraTIOn[i]) != null)
				{
					document.getElementById(GETresulTAFterSEPAraTIOn[i]+'_Td').innerHTML='<select name="'+GETresulTAFterSEPAraTIOn[i]+'" id="'+GETresulTAFterSEPAraTIOn[i]+'">'+GETresulTAFterSEPAraTIOn[0]+'</select>';
				}
				
			}
			
		}
		
    }
}




